#include "json.h"
#include "metaSet.h"
#include "jt.h"

int main()
{
	testInfo data;
	strcpy(data.hopsIp, "Dxsetr");
	data.offsetTime = 0x9988;
	data.abb = malloc(sizeof(cdn));
	data.abb->a = 1000;
	data.abb->b = 2000;
	cdn cdnR1 = {
		.a = 100,
		.b = 200,
		};
	cdn cdnR2 = {
		.a = 300,
		.b = 400,
		};
	list_node_cdn * node = malloc(sizeof(list_node_cdn));
	if (node == NULL)
		return -1;
	memset(node, 0x00, sizeof(list_node_cdn));
	node->data = cdnR1;
	
	uint32 maxListCount = MAX_LIST_COUNT;
	init_cdn_list(&(data.cdnHead));
	set_config_cdn_list(&(data.cdnHead), &maxListCount);
	
	insert_into_cdn_list_tail(node, &data.cdnHead);// add the trituple node to the list

	
	node = malloc(sizeof(list_node_cdn));
	if (node == NULL)
		return -1;
	memset(node, 0x00, sizeof(list_node_cdn));
	node->data = cdnR2;
	insert_into_cdn_list_tail(node, &data.cdnHead);// add the trituple node to the list
	node = malloc(sizeof(list_node_cdn));
	if (node == NULL)
		return -1;
	memset(node, 0x00, sizeof(list_node_cdn));
	node->data = cdnR2;
	insert_into_cdn_list_tail(node, &data.cdnHead);// add the trituple node to the list
	//insert_into_cdn_list_tail(node, &data.cdnHead);// add the trituple node to the list

	get_first_cdn_node(&data.cdnHead)->data.a;
	int cnt = get_cdn_list_node_count(&data.cdnHead);
	
	printf("Addresse data:%08X data.offsetTime:%08X, cdnHead: %08X, list_head:%08X count:%u\n", 
		&data, &(data.offsetTime), &(data.cdnHead), &(data.cdnHead.list_head), cnt);

	listNode* p = firstNode(&(data.cdnHead));
	list_node_cdn* pNode = get_first_cdn_node(&data.cdnHead);
	printf("cdn1:%08X  :%08X data:%08X  a:%d \n", 
		p, pNode, &(pNode->data), pNode->data.a);

	jsonStruct json;
	initJsonPara(&json);

	encapsulateRet ret_enc = encapsulateJsonList(&json, "testInfo", &data, meta_testInfo, STB_DATA_BEAN);
	int ret = format(&json);
	char* str = getJsonEncapsulateStr(&json);

	printf("the json is: \n%s\n", str);

	freeJson(&json);
	
	return 0;
}

